package com.minicode.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.StrictMode;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;

public class AbstractActivity extends Activity {

	/*
	 * Screen
	 */
	public int WIDTH;
	public int HEIGHT;
	public String sharedPreferencesName;

	public void init(boolean title) {
		if (!title) {
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
		}
		/*
		 * Popuplar icin ekran boyutu
		 */
		Display display = getWindowManager().getDefaultDisplay();
		WIDTH = display.getWidth();
		HEIGHT = display.getHeight();
	}

	public void init(boolean title, String sharedPreferencesName) {
		if (!title) {
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
		}
		/*
		 * Popuplar icin ekran boyutu
		 */
		Display display = getWindowManager().getDefaultDisplay();
		WIDTH = display.getWidth();
		HEIGHT = display.getHeight();

		this.sharedPreferencesName = sharedPreferencesName;
	}

	public boolean isAccessInternet() {
		ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		if (networkInfo != null && networkInfo.isConnected()) {
			return true;
		} else {
			return false;
		}
	}

	public void activeStrictMode() {

		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
				.permitAll().build();
		StrictMode.setThreadPolicy(policy);

	}

	public void SavePreferencesString(String key, String value) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public void SavePreferencesBoolean(String key, boolean value) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public void SavePreferencesInt(String key, int value) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public void SavePreferencesLong(String key, long value) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		editor.putLong(key, value);
		editor.commit();
	}

	public void SavePreferencesFloat(String key, float value) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		editor.putFloat(key, value);
		editor.commit();
	}

	public String LoadPreferencesString(String key, String default_) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		String result = sharedPreferences.getString(key, default_);
		return result;
	}

	public int LoadPreferencesInt(String key, int default_) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		int result = sharedPreferences.getInt(key, default_);
		return result;
	}

	public long LoadPreferencesLong(String key, long default_) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		long result = sharedPreferences.getLong(key, default_);
		return result;
	}

	public float LoadPreferencesFloat(String key, float default_) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		float result = sharedPreferences.getFloat(key, default_);
		return result;
	}

	public boolean LoadPreferencesString(String key, boolean default_) {
		SharedPreferences sharedPreferences = getSharedPreferences(
				sharedPreferencesName, MODE_PRIVATE);
		boolean result = sharedPreferences.getBoolean(key, default_);
		return result;
	}
}
